<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <title>后台管理</title>
    <%@include file="../common/common.jsp"%>
</head>

<body>

<%@include file="navTop.jsp"%>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="<%=path%>/admin/scenic_spot">景区管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="<%=path%>/admin/hotel">酒店管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li class="active"><a href="<%=path%>/admin/ticket">票务管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="<%=path%>/admin/user">用户管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="<%=path%>/admin/index">首页设置</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h2 class="sub-header">票务管理</h2>
            <div class="table-responsive">
                <table id="ticketDg" class="table table-striped">

                </table>
            </div>
            <div id="toolbar" class="btn-group">
                <form class="form-inline">
                    <div class="form-group">
                        <label for="startStation">出发站：</label>
                        <input type="text" class="form-control" name="startStation" id="startStation" placeholder="昆明">
                    </div>
                    <div class="form-group">
                        <label for="lastStation">到达站：</label>
                        <input type="text" class="form-control" id="lastStation" placeholder="石林">
                    </div>
                    <div class="form-group">
                        <label for="startTime">出发日期：</label>
                        <input type="text" class="form-control" id="startTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'%y-%M-{%d}'})" readonly />
                    </div>
                    <button type="button" class="btn btn-info" id="btnSelect">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>查询
                    </button>
                    <button type="button" class="btn btn-info"  data-toggle="modal" data-target="#ticketInsertModal">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="ticketInsertModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新加票务</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label for="iTrainInfo" class="col-sm-3 control-label">车次信息:</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" id="iTrainInfo" placeholder="10字以内"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="iStartStation" class="col-sm-3 control-label">起点站：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="iStartStation" placeholder="10字以内"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="iStartTime" class="col-sm-3 control-label">出发时间：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="iStartTime"
                                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-{%d}'})" readonly />
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="iLastStation" class="col-sm-3 control-label">到达站：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="iLastStation" placeholder="10字以内">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="iLastTime" class="col-sm-3 control-label">到达时间：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="iLastTime"
                                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-{%d}'})" readonly />
                            </div>
                        </div>
                        <div class="form-group text-center">
                            <p id="showMsg" style="color: red;display: none"></p>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="btnAdd">添加</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        initTable();
        btnAdd();
    });
    var initTable = function () {

        //加载表格
        $('#ticketDg').bootstrapTable({
            //searchAlign: 'left',
            search: true,   //显示隐藏搜索框
            showHeader: true,     //是否显示列头
            //classes: 'table-no-bordered',
            showLoading: false,
            undefinedText: '',
            showFullscreen: false,
            // toolbarAlign: 'left',
            // paginationHAlign: 'right',
            silent: false,
            //url: CONTEXT_PATH+"/Ticketinfo/pageList",
            //method: 'get',                      //请求方式（*）
            ajax:function(request) {
                console.log(request);
                $.ajax({
                    url:CONTEXT_PATH+"/Ticketinfo/pageList",
                    type:"POST",
                    dataType:"json",
                    data:request.data,
                    success:function(data){
                        var result={
                            "rows": data.pageList,
                            "total": data.totalCount
                        };
                        request.success({
                            "rows": data.pageList,
                            "total": data.totalCount
                        });
                        $('#ticketDg').bootstrapTable('load', result);
                    },
                    error:function(error){
                        console.log(error);
                    }
                })
            },
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 20, 30],        //可供选择的每页的行数（*）
            search: false,                      //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            showColumns: false,                  //是否显示选择所有的列
            showRefresh: false,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 550,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "id",                     //每一行的唯一标识，一般为主键列
            showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
            cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            showExport: false,
            exportDataType: 'all',
            exportDataType: "selected",        //导出checkbox选中的行数
            paginationLoop: false,             //是否无限循环
            data_local: "zh-CN",
            queryParams:function (params) {
                var cond = {};
                cond['offset']=params.offset;
                cond['pagesize']=params.limit;
                cond['startStation'] = $("#startStation").val();
                cond['lastStation'] = $("#lastStation").val();
                cond['startTime'] = $("#startTime").val();
                var param = Param.getReadCmd();
                Param.buildParam(param, cond);
                return param;
            },
            responseHandler: function (res) {
                //这里注意，这里是后台接口返回的数据，需要把返回的数据分别对接rows和total 用于分页和展示
                return {
                    "rows": res.pageList,
                    "total": res.totalCount
                };
            },
            columns: [
                { field: 'id', title: '序号', visible: false },
                { field: 'trainInfo', title: '车次信息' },
                { field: 'startStation', title: '出发站' },
                { field: 'startTime', title: '出发时间' ,formatter:function (value, row, index) {
                        return Util.date.format(new Date(value),"yyyy年MM月dd日 hh时mm分ss秒")
                    }},
                { field: 'runTime', title: '运行时长' },
                { field: 'lastStation', title: '到达站' },
                { field: 'lastTime', title: '到达时间' ,formatter:function (value, row, index) {
                        return Util.date.format(new Date(value),"yyyy年MM月dd日 hh时mm分ss秒")
                    }},
                {
                    field: '', title: '操作',
                    formatter: function (value, row, index) {
                        return "<button class=\"btn btn-warning\" onclick=\"deletedg('" + row.id + "')\"> 删除 </button>";
                    }
                }],
            onLoadSuccess: function (result) {  //加载成功时执行
                console.log(result)
            },
        });
    };
    var deletedg =function (id) {
        Util.doGet("/admin/ticketManage/delete/"+id,null,function () {
            $('#dg').bootstrapTable("refresh");
        });
    };

    var btnAdd=function () {
        $("#btnAdd").click(function () {
            var train=$("#iTrainInfo").val();
            var startSt=$("#iStartStation").val();
            var startTime=$("#iStartTime").val();
            var lastStat=$("#iLastStation").val();
            var lastTime=$("#iLastTime").val();
            var cond = {};
            if(!Util.nvl(train)&&!Util.nvl(startSt)
                &&!Util.nvl(startTime)&&!Util.nvl(lastStat)&&!Util.nvl(lastTime)){
                $("#showMsg").hide();
                cond['train'] = train;
                cond['startSt'] = startSt;
                cond['startTime'] = startTime;
                cond['lastStat'] = lastStat;
                cond['lastTime'] = lastTime;
            }else{
                $("#showMsg").text("有选项为空！请检查！");
                $("#showMsg").show();
                return;
            }
            var param = Param.getReadCmd();
            Param.buildParam(param, cond);
            console.log(param);
            Util.post("/admin/ticketManage/insert",param,function (result) {
                if(result.code===200){
                    $('#ticketInsertModal').modal('hide');
                    swal("提示！","添加成功！","success");
                }else{
                    $("#showMsg").text("发生错误");
                    $("#showMsg").show();
                }
            })
        });
    }

</script>
</body>

</html>